<template>
  <div>
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      ref="date"
      @confirm="getuploadProfile"
      @cancel="$parent.$parent.show3 = false"
    />
  </div>
</template>

<script>
import dayjs from 'dayjs'
import { getuploadProfile } from '@/api'
export default {
  data() {
    return {
      minDate: new Date(2020, 0, 1),
      maxDate: new Date(2025, 10, 1),
      currentDate: this.$parent.$parent.UserInfo.birthday
      // this.$parent.$parent.UserInfo.birthday
    }
  },
  mounted() {
    this.getuploadProfile()
  },
  methods: {
    async getuploadProfile(value) {
      try {
        const data = { birthday: this.currentDate }
        await getuploadProfile({
          birthday: dayjs(value).format('YYYY-MM-DD')
        })
        console.log(data)
        // this.dayList = this.$refs.date.getPicker().getValues().join('-')
        // console.log(this.dayList)
        this.$parent.$parent.getUserInfo()
        this.$parent.$parent.show3 = false
        this.$toast.success('年龄修改成功!')
      } catch (error) {
        this.$toast.fail('年龄修改失败!')
      }
    }
  }
  // computed: {
  //   currentDate: {
  //     get() {
  //       const daaa = this.dayList.split('-')
  //       console.log(daaa)
  //       daaa[1] -= 1
  //       return new Date(...daaa)
  //     },
  //     set() {}
  //   }
  // }
}
</script>

<style scoped lang="less"></style>
